﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TankBattle.Models
{
    public class Obstruction: GameObject
    {
        #region Variable

        private int type;
        private bool invisible;

        #endregion

        #region Construction 

        public Obstruction()
        { }
        public Obstruction(Texture2D texture, Vector2 position, int width, int height,int typeObstruction)
        {
            this.type = typeObstruction;
            Intallization(texture, position, width, height);          
        }
        public Obstruction(Texture2D texture, Vector2 position,int typeObstruction)
        {
            this.type = typeObstruction;
            Intallization(texture, position,
                Constant.OBSTRUCTION_WIDTH, Constant.OBSTRUCTION_HEIGHT);
        }
        
        #endregion 

        #region Properties

        public bool BROKEN
        {
            get
            {
                if (life > Constant.ZERO) life--;
                if (life == Constant.ZERO)
                    return true;
                else
                    return false;
            }
        }
        public override bool Hidden
        {
            get { return invisible; }
        }
        public override Rectangle Polygon
        {
            get
            {
                return new Rectangle((int)Position.X,(int)Position.Y,
                    (int)(width), (int)(height - Constant.MOVE_RADIUS_Y));
            }
        }

        #endregion

        #region Function

        private void SetLife()
        {
            switch (type)
            {
                case (Constant.OBSTRUCTION_BRICK): life = Constant.LIFE_BRICK; invisible = false;
                    break;
                case (Constant.OBSTRUCTION_GRASS): life = Constant.LIFE_UNDEAD; invisible = true;
                    break;
                case (Constant.OBSTRUCTION_RIVER): life = Constant.LIFE_UNDEAD; invisible = true;
                    break;
                case (Constant.OBSTRUCTION_STONE): life = Constant.LIFE_STONE; invisible = false;
                    break;
            }
        }
        public override void  Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture,
                new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height),
                Color.White);
        }
        protected override void Intallization(Texture2D texture, Vector2 position, int width, int height)
        {
            base.Intallization(texture, position, width, height);
            SetLife();
        }

        #endregion 
    }
}
